//
//  PoemEnviromentKey.swift
//  ChinaPoem-Swift
//
//  Created by JunMing on 2023/2/26.
//

import SwiftUI

extension EnvironmentValues {
    var modalTransitionPercent: CGFloat {
        get { return self[ModalTransitionKey.self] }
        set { self[ModalTransitionKey.self] = newValue }
    }
    
    var isVIP: Bool {
        get { self[VIPEnviromentKey.self] }
        set { self[VIPEnviromentKey.self] = newValue }
    }
    
    var isPoemLike: Bool {
        get { self[PoemEnviromentKey.self] }
        set { self[PoemEnviromentKey.self] = newValue }
    }
    
    var isScrolling: Bool {
        get { self[IsScrollingValueKey.self] }
        set { self[IsScrollingValueKey.self] = newValue }
    }
    
    var polygonSides: Double {
        get { self[PolygonSideValue.self] }
        set { self[PolygonSideValue.self] = newValue }
    }
}

struct PolygonSideValue: EnvironmentKey {
    static var defaultValue: Double = 4.0
}

public struct ModalTransitionKey: EnvironmentKey {
    public static let defaultValue: CGFloat = 0
}

struct PoemEnviromentKey: EnvironmentKey {
    static let defaultValue: Bool = false
}

struct IsScrollingValueKey: EnvironmentKey {
    static var defaultValue = false
}

struct MinValueKey: PreferenceKey {
    public static var defaultValue: CGRect = .zero
    public static func reduce(value: inout CGRect, nextValue: () -> CGRect) {
        value = nextValue()
    }
}

struct ScrollPreferenceKeys: PreferenceKey {
    static var defaultValue: CGFloat = 0
    static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
        value = nextValue()
    }
}

struct VIPEnviromentKey: EnvironmentKey {
    static let defaultValue: Bool = false
}

struct TabPreferencKey: PreferenceKey {
    static var defaultValue: CGFloat = 0
    static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
        value = nextValue()
    }
}
